#include "myc.h"

struct var *lastvar=NULL;

struct var *add_var(struct token *name,struct vtype typ,int loc) {
	struct var *nev=calloc(1,sizeof(*nev));
	nev->name=strndup(name->str,name->len);
	nev->type=typ;
	nev->loc=loc;
	nev->next=lastvar;
	return lastvar=nev;
}

void del_var() {
	struct var *olv=lastvar;
	lastvar=lastvar->next;
	free(olv->name);
	free(olv);
}

struct var *find_var(struct token *tok) {
	struct var *vlist=lastvar;
	while (vlist) {
		if (tokis(tok,vlist->name)) return vlist;
		vlist=vlist->next;
	}
	return NULL;
}
